package com.avantis.common.msg;


import com.avantis.common.enums.StateEnum;
import lombok.Data;
import org.springframework.data.domain.Page;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName YResult
 * @Description Rest 响应数据
 * @Author kirago
 * @Date 2018/11/26 19:46
 * @Version 1.0
 **/
@Data
public class YResult implements Serializable {

	/**
	 * 响应业务状态
	 */
	private Integer status;

	/**
	 * 返回的数据
	 */
	private Object data;

	/**
	 * 错误信息
	 */
	private String error;

	/**
	 * 返回总页数
	 */
	private long pageSize;

	/**
	 * 本页返回数量
	 */
	private Integer total;

	/**
	 * 请求成功
	 * @param status
	 */
	public YResult(Integer status) {
		this.status = status;
	}

	/**
	 * 请求成功并携带数据
	 * @param status
	 * @param data
	 */
	public YResult(Integer status, Object data) {
		this.status = status;
		this.data = data;
	}

	/**
	 * 请求成功被携带参数与页数
	 * @param status
	 * @param data
	 * @param pageSize
	 * @param total
	 */
	public YResult(Integer status, Object data, long pageSize, Integer total) {
		this.status = status;
		this.data = data;
		this.pageSize = pageSize;
		this.total = total;
	}

	/**
	 * 请求失败
	 * @param status
	 * @param error
	 */
	public YResult(Integer status, String error) {
		this.status = status;
		this.error = error;
	}

	public static  YResult ok(){
		return new YResult(StateEnum.SUCCESS.getState());
	}

	public static YResult ok(Object data){
		return new YResult(StateEnum.SUCCESS.getState(),data);
	}

	public static YResult warn(String warn){return new YResult(StateEnum.WARN.getState(),warn);}

	public static YResult error(String error){
		return new YResult(StateEnum.ERROR.getState(),error);
	}

	public static YResult ok(Object data,long pageSize,Integer total){
		return new YResult(StateEnum.SUCCESS.getState(),data,pageSize,total);
	}
}